<?php

/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    
 * @package     _home
 * @copyright   Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
class Zhishidi_Express_Block_Adminhtml_Group_Grid extends Mage_Adminhtml_Block_Widget_Grid {

    /**
     * Initialize grid settings
     *
     */
    protected function _construct() {

        parent::_construct();
        $this->setId('expressGroupGrid');
        $this->setUseAjax(true);
       
        #$this->setSaveParametersInSession(true);
    }
 

    /**
     * Prepare product collection
     *
     * @return Zhishidi_Express_Block_Adminhtml_Dailydeals_Grid
     */
    protected function _prepareCollection() {
        $collection = Mage::getModel('zhishidi_express/group')
                        ->getCollection();
        $this->setCollection($collection);
        return parent::_prepareCollection();
    }

    /**
     * Prepare grid columns
     *
     * @return Zhishidi_Express_Block_Adminhtml_Dailydeals_Grid
     */
    protected function _prepareColumns() {
        $this->addColumn('id', array(
            'header' => Mage::helper('zhishidi_express')->__('ID'),
            'sortable' => true,
            'width' => '60px',
            'index' => 'group_id'
        ));


        $this->addColumn('group_name', array(
            'header' => Mage::helper('zhishidi_express')->__('Group Name'),
            'align' => 'left',
            'index' => 'group_name',
        ));
      

        $this->addColumn('group_status', array(
            'header' => Mage::helper('zhishidi_express')->__('Status'),
            'index' => 'group_status',
            'type' => 'options',
            'options' => array(
                'hidden' => Mage::helper('zhishidi_express')->__('Disabled'),
                'public' => Mage::helper('zhishidi_express')->__('Enabled'),
            ),
        ));



        $this->addColumn('action',
                array(
                    'header' => Mage::helper('zhishidi_express')->__('Action'),
                    'width' => '100',
                    'type' => 'action',
                    'getter' => 'getId',
                    'actions' => array(
                        array(
                            'caption' => Mage::helper('zhishidi_express')->__('Edit'),
                            'url' => array('base' => '*/*/edit'),
                            'field' => 'id'
                        )
                    ),
                    'filter' => false,
                    'sortable' => false,
                    'index' => 'group_id',
                    'is_system' => true,
        ));



        return parent::_prepareColumns();
    }

    protected function _afterLoadCollection() {
        $this->getCollection()->walk('afterLoad');
        parent::_afterLoadCollection();
    }
 

    protected function _prepareMassaction() {
        $this->setMassactionIdField('group_id');
        $this->getMassactionBlock()->setFormFieldName('mass_action_ids');



        $this->getMassactionBlock()->addItem('delete', array(
            'label' => Mage::helper('zhishidi_express')->__('Delete'),
            'url' => $this->getUrl('*/*/massDelete'),
            'confirm' => Mage::helper('zhishidi_express')->__('Are you sure?')
        ));


        $this->getMassactionBlock()->addItem('status', array(
            'label' => Mage::helper('zhishidi_express')->__('Change status'),
            'url' => $this->getUrl('*/*/massStatus', array('_current' => true)),
            'additional' => array(
                'visibility' => array(
                    'name' => 'group_status',
                    'type' => 'select',
                    'class' => 'required-entry',
                    'label' => Mage::helper('zhishidi_express')->__('Status'),
                    'values' => array(
                        'hidden' => Mage::helper('zhishidi_express')->__('Disabled'),
                        'public' => Mage::helper('zhishidi_express')->__('Enabled'),
                    ),
                )
            )
        ));
        return $this;
    }

    public function getRowUrl($row) {
        return $this->getUrl('*/*/edit', array('id' => $row->getId()));
    }

    public function getGridUrl() {
        return $this->getUrl('*/*/grid', array('_current' => true));
    }

}
